/**
 * 
 */
package com.rhf.ui.admin.actions.general;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.rhf.core.commons.logging.AppLog;
import com.rhf.core.commons.logging.AppLogManager;
import com.rhf.ui.admin.session.UserSessionKey;

/**
 * Action pour se d�connecter de la partie administration
 * 
 * @author fabiensaulnier
 * 
 */
public class LogoutAction extends Action {

	/**
	 * Log manageur
	 */
	private AppLog appLog = AppLogManager.getUiLogger();

	/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.apache.struts.action.Action#execute(org.apache.struts.action.
	 * ActionMapping, org.apache.struts.action.ActionForm,
	 * javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse)
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

		this.appLog.debug("Debut de l'action [Se d�connecter]");

		ActionForward actionForward = null;

		try {

			// Effacement de la session
			request.getSession().removeAttribute(UserSessionKey.USER_SESSION);

			// Redirection / Mapping
			actionForward = mapping.findForward("success");

		} catch (Exception e) {
			actionForward = mapping.findForward("error");
			this.appLog.error("Une erreur est survenue lors de la d�connection", e);
			throw new Exception("Une erreur est survenue lors de la d�connection", e);
		}

		this.appLog.debug("Fin de l'action [Se d�connecter]");

		// Redirection
		String path = actionForward.getPath();
		ActionForward newActionForward = new ActionForward(actionForward);
		newActionForward.setPath(path);
		return newActionForward;
	}
}
